﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace FileEfCore.DbContexts;

public class ServerDesignTimeDbContextFactory: IDesignTimeDbContextFactory<ServerFileDbContext>
{
    public ServerFileDbContext CreateDbContext(string[] args)
    {
        var dbContextOptionsBuilder = new DbContextOptionsBuilder<ServerFileDbContext>();
        var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        var dbPath = Path.Combine(homeDir, ".ums-file-server/fileinfo.db");
        var connectionString = $"Data Source={dbPath}";
        dbContextOptionsBuilder.UseSqlite(connectionString);
        return new ServerFileDbContext(dbContextOptionsBuilder.Options);
    }
}